package basic;

import java.util.LinkedList;
import stats.ClubStats;
import misc.BasicClubOperations;
import misc.Role;

public class Club implements BasicClubOperations {

	private String name = "";
	private League league = null;
	private ClubStats stats = null;
	private LinkedList<Player> players = null;
	
	public Club() {
		super();
		this.name = "";
		this.league = null;
		this.stats = null;
		this.players = null;
	}

	public Club(String name, League league) {
		super();
		this.name = name;
		this.league = league;
		this.stats = new ClubStats();
		this.players = new LinkedList<Player>();
	}
	
	@Override
	public Player createPlayer(String firstName, String lastName,String dateOfBirth, Role role, Club club, Country country) {
		if (firstName!= null && lastName!= null && dateOfBirth != null && role != null && club != null && country != null){
			return new Player(firstName, lastName, dateOfBirth, role, club, country);
		}
		else {
			System.out.println("error, not all player data is entered");
		}
		return null;
	}

	public void addPlayer(Player player) {
		if (player != null)
			players.add(player);
	}

	@Override
	public void removePlayer(Player player) {
		for (int i = 0; i < players.size(); i++){
			if (players.get(i).equals(player)){
				players.remove(i);
			}
		}
	}

	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public League getLeague() {
		return league;
	}
	public void setLeague(League league) {
		this.league = league;
	}
	public LinkedList<Player> getPlayers() {
		return players;
	}
	public void setStats(ClubStats stats) {
		this.stats = stats;
	}
	public ClubStats getStats() {
		return stats;
	}
	public Object[] getClubLeagueView(){
		Object[] parameters = new Object[9];
		parameters[0] = stats.getRank();
		parameters[1] = getName();
		parameters[2] = stats.getWins();
		parameters[3] = stats.getDraws();
		parameters[4] = stats.getLoses();
		parameters[5] = stats.getGoals();
		parameters[6] = stats.getConcieved();
		parameters[7] = stats.getDifference();
		parameters[8] = stats.getWins()*3 + stats.getDraws();
		return parameters;
	}
	
}
